<template>
  <a-modal
    :title="`发工资`"
    :width="640"
    :visible="visible"
    :confirmLoading="loading"
    @ok="
      () => {
        $emit('ok')
      }
    "
    @cancel="
      () => {
        $emit('cancel')
      }
    "
  >
    <a-spin :spinning="loading">
      <a-form :form="form" v-bind="formLayout">
        <a-form-item v-show="false">
          <a-input v-decorator="['id']" name="id" />
        </a-form-item>
        <a-form-item label="实发工资">
          <a-input v-decorator="['finalWages', { initialValue: '0' }]" disabled prefix="￥" placeholder="请输入实发工资" name="finalWages" />
        </a-form-item>
        <a-form-item label="记账账户">
          <a-select v-decorator="['accId']" placeholder="请选择" name="accId" >
            <a-select-option :value="i.id" v-for="i in this.option" :key="i.value">{{ i.accName }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="归属店面">
          <a-select v-decorator="['storeId']" placeholder="请选择" name="storeId" >
            <a-select-option :value="i.id" v-for="i in this.storeOption" :key="i.value">{{ i.storeName }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="发工资日期">
          <a-date-picker v-decorator="['payOffDate']" style="width: 100%" name="payOffDate" valueFormat="YYYY-MM-DD"/>
        </a-form-item>
        
      </a-form>
    </a-spin>
  </a-modal>
</template>
    
<script>
import pick from 'lodash.pick'
import { getStoreListUsingPOST } from '@/api/api/mendianguanli.ts'
import { getStAccountListUsingGET } from '@/api/api/qiantaizhangwu.ts'
// 表单字段
const fields = ['finalWages','accId','storeId','payOffDate', 'id']

export default {
  props: {
    visible: {
      type: Boolean,
      required: true,
    },
    loading: {
      type: Boolean,
      default: () => false,
    },
    model: {
      type: Object,
      default: () => null,
    },
  },
  data() {
    this.formLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 13 },
      },
    }
    return {
      sp: true,
      yys: true,
      AA: true,
      queryParam: {
        pageNo: 1,
        pageSize: 999,
        queryCondition: '',
        status: 1,
      },
      storeOption:[],
      option:[],
      form: this.$form.createForm(this),
    }
  },
  created() {
    this.handleStore()
    this.handle()
    // 防止表单未注册
    fields.forEach((v) => this.form.getFieldDecorator(v))

    // 当 model 发生改变时，为表单设置值
    this.$watch('model', () => {
      this.model && this.form.setFieldsValue(pick(this.model, fields))
    })
  },
  methods: {
    handle() {
      getStAccountListUsingGET({...this.queryParam,typeList:'0,1'})
        .then((res) => {
          this.option = res.data.list
        })
        .catch((error) => {
          this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
        })
    },
    handleStore(){
        getStoreListUsingPOST(this.queryParam).then((res) => {
          this.storeOption = res.data.list
        })
        .catch((error) => {
          this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
        })
      },
    handleSP() {
      this.sp = !this.sp
    },
    handleAA() {
      this.AA = !this.AA
    },
    handleYYS() {
      this.yys = !this.yys
    },
  },
}
</script>
  <style>
.ant-input-group-addon {
  padding: 0;
}
</style>